export default class CustomPromise {
    state: string
    data: any
    errorData: any
    constructor(cb: (arg0: (data: any) => void, arg1: (data: any) => void) => void) {
        this.state = 'panding'
        // this.code = code
        cb(this.resolve, this.reject)
        console.log('CustomPromise', this)
    }
    resolve = (data: any) => {
        console.log('resolved', this, data)

        if (this.state === 'panding') {
            this.state = 'fulfilled'
            this.data = data
        }
    }
    reject = (data: any) => {
        if (this.state === 'panding') {
            this.state = 'rejected'
            this.errorData = data
        }
    }
    then = (cb: (arg0: any) => any) => {
        console.log('then', this);
        
        if (this.state === 'resolve') {
            cb && cb(this.data)
        }
    }
    catch = (cb: (arg0: any) => any) => {
        if (this.state === 'reject') {
            cb && cb(this.errorData)
        }
    }
}